package ar.edu.caece.pl.asem.model.impl.treeelements;

import ar.edu.caece.pl.asem.model.impl.SymbolTable;
import ar.edu.caece.pl.asem.temp.TemporalGenerator;

public class Variable extends SimboloGenerico {

	public Variable(String name, int type) {
		super(name, type);
		this.label = "VARIABLE";
	}

	@Override
	public String toString() {
		return this.getLabel() + ": " + this.getName() + " ("
				+ SymbolTable.getVerboseType(this.getType()) + ")";
	}

	@Override
	public void generateASMCode() {
		StringBuffer sb = new StringBuffer();
		if(!(this.parent instanceof Declaraciones)){
			TemporalGenerator.getInstance().generateTemporal();			
			this.place = TemporalGenerator.getInstance().getActualTemporal();
			sb.append("\t mov ax, " + this.getEnvName() + "_" + this.getName() + " \n");
			sb.append("\t mov " + this.place + ",ax \n");
		}
		
		if(this.parent instanceof Declaraciones){
			String key = this.getEnvName() + "_" + this.getName();
				sb.append(key + " dw "
						+ this.getValue() + " \n");
		}
		
		this.code = sb.toString();
		
	}

}
